
const abi = require('../abi/MessageTransmitter');
const {ethers} = require('ethers');
class MessageTransmitter {
    constructor(url, scAddr){
        this.url = url;
        this.scAddr = scAddr;
        this.provider = new ethers.providers.JsonRpcProvider(url);
        this.scInst = new ethers.Contract(this.scAddr, abi, this.provider);
    }

    async receiveMessage(wallet,message, attestation) {
        let newWallet = wallet.connect(this.provider);
        let newScInst = this.scInst.connect(newWallet);
        let tx = await newScInst.receiveMessage(message, attestation);
        let receipt = await tx.wait();
        return receipt;
    }

}


module.exports = MessageTransmitter;